package org.zpmis.domain.project.vo;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.zpmis.domain.project.model.Project;

import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

@Data
public class ProjectListVo {
    /**
     * 项目id
     */
    private Long id;

    /**
     * 项目名称
     */
    private String name;

    /**
     * 项目代号
     */
    private String code;

    /**
     * 项目开始时间
     */
    private String startTime;

    /**
     * 项目总工期
     */
    private BigDecimal totalTime;

    /**
     * 项目结束时间
     */
    private String endTime;

    /**
     * 合同id
     */
    private Long contractId;

    /**
     * 项目描述
     */
    private String description;

    /**
     * 项目状态 0未开始 1进行中 2已完结 3失效
     */
    private Integer status;

    /**
     * 归档状态 0未归档 1已归档
     */
    private Integer archiveStatus;

    /**
     * 附件
     */
    private String attachment;

    /**
     * 源码位置
     */
    private String sourceLocation;

    /**
     * 创建人id
     */
    private Long createId;

    /**
     * 创建人
     */
    private String createPerson;

    /**
     * 创建时间
     */
    private String createTime;

    public ProjectListVo(Project project) {
        this.id = project.getId();
        this.name = project.getName();
        this.code = project.getCode();
        this.startTime = project.getStartTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(project.getStartTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        this.totalTime = project.getTotalTime();
        this.endTime = project.getEndTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(project.getEndTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        this.contractId = project.getContractId();
        this.description = project.getDescription();
        this.status = project.getStatus();
        this.archiveStatus = project.getArchiveStatus();
        this.attachment = project.getAttachment();
        this.sourceLocation = project.getSourceLocation();
        this.createId = project.getCreateId();
        this.createPerson = project.getCreatePerson();
        this.createTime = project.getCreateTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(project.getCreateTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
    }
}